/*     */ package blockbuster.components.appearance;
/*     */ 
/*     */ import blockbuster.BedrockMaterial;
/*     */ import blockbuster.BedrockScheme;
/*     */ import blockbuster.components.BedrockComponentBase;
/*     */ import blockbuster.components.IComponentParticleRender;
/*     */ import blockbuster.emitter.BedrockEmitter;
/*     */ import blockbuster.emitter.BedrockParticle;
/*     */ import blockbuster.math.molang.MolangException;
/*     */ import blockbuster.math.molang.MolangParser;
/*     */ import blockbuster.math.molang.expressions.MolangExpression;
/*     */ import blockbuster.utils.Interpolations;
/*     */ import blockbuster.utils.RLUtils;
/*     */ import com.google.gson.JsonElement;
/*     */ import com.google.gson.JsonObject;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import javax.vecmath.Tuple4f;
/*     */ import javax.vecmath.Vector3d;
/*     */ import javax.vecmath.Vector3f;
/*     */ import javax.vecmath.Vector4f;
/*     */ import net.minecraft.client.renderer.BufferBuilder;
/*     */ import net.minecraft.util.ResourceLocation;
/*     */ 
/*     */ public class BedrockComponentCollisionAppearance
/*     */   extends BedrockComponentAppearanceBillboard
/*     */   implements IComponentParticleRender {
/*  28 */   public BedrockMaterial material = BedrockMaterial.OPAQUE;
/*  29 */   public ResourceLocation texture = BedrockScheme.DEFAULT_TEXTURE;
/*     */   
/*  31 */   public MolangExpression enabled = MolangParser.ZERO;
/*     */ 
/*     */   
/*     */   public boolean lit;
/*     */ 
/*     */   
/*     */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/*  38 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*     */     
/*  40 */     JsonObject element = elem.getAsJsonObject();
/*     */     
/*  42 */     if (element.has("enabled")) this.enabled = parser.parseJson(element.get("enabled")); 
/*  43 */     if (element.has("lit"))
/*     */     {
/*  45 */       this.lit = element.get("lit").getAsBoolean();
/*     */     }
/*     */     
/*  48 */     if (element.has("material"))
/*     */     {
/*  50 */       this.material = BedrockMaterial.fromString(element.get("material").getAsString());
/*     */     }
/*     */     
/*  53 */     if (element.has("texture")) {
/*     */       
/*  55 */       String texture = element.get("texture").getAsString();
/*     */       
/*  57 */       if (!texture.equals("textures/particle/particles"))
/*     */       {
/*  59 */         this.texture = RLUtils.create(texture);
/*     */       }
/*     */     } 
/*     */     
/*  63 */     return super.fromJson((JsonElement)element, parser);
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public JsonElement toJson() {
/*  69 */     JsonObject object = new JsonObject();
/*     */     
/*  71 */     object.add("enabled", this.enabled.toJson());
/*  72 */     object.addProperty("lit", Boolean.valueOf(this.lit));
/*  73 */     object.addProperty("material", this.material.id);
/*     */     
/*  75 */     if (this.texture != null && !this.texture.equals(BedrockScheme.DEFAULT_TEXTURE))
/*     */     {
/*  77 */       object.addProperty("texture", this.texture.toString());
/*     */     }
/*     */ 
/*     */     
/*  81 */     JsonObject superJson = (JsonObject)super.toJson();
/*  82 */     Set<Map.Entry<String, JsonElement>> entries = superJson.entrySet();
/*     */     
/*  84 */     for (Map.Entry<String, JsonElement> entry : entries)
/*     */     {
/*  86 */       object.add(entry.getKey(), entry.getValue());
/*     */     }
/*     */     
/*  89 */     return (JsonElement)object;
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public void preRender(BedrockEmitter emitter, float partialTicks) {}
/*     */ 
/*     */ 
/*     */   
/*     */   public void render(BedrockEmitter emitter, BedrockParticle particle, BufferBuilder builder, float partialTicks) {
/*  99 */     boolean tmpLit = false;
/*     */     
/* 101 */     if (!particle.isCollisionTexture(emitter)) {
/*     */       
/* 103 */       if (particle.isCollisionTinting(emitter)) {
/*     */         
/* 105 */         tmpLit = emitter.lit;
/* 106 */         emitter.lit = this.lit;
/* 107 */         ((BedrockComponentAppearanceBillboard)emitter.scheme.get(BedrockComponentAppearanceBillboard.class)).render(emitter, particle, builder, partialTicks);
/* 108 */         emitter.lit = tmpLit;
/*     */       } 
/*     */       
/*     */       return;
/*     */     } 
/* 113 */     if (!particle.isCollisionTinting(emitter)) {
/*     */ 
/*     */       
/* 116 */       tmpLit = this.lit;
/* 117 */       this.lit = emitter.lit;
/*     */     } 
/*     */     
/* 120 */     calculateUVs(particle, partialTicks);
/*     */ 
/*     */     
/* 123 */     double px = Interpolations.lerp(particle.prevPosition.x, particle.position.x, partialTicks);
/* 124 */     double py = Interpolations.lerp(particle.prevPosition.y, particle.position.y, partialTicks);
/* 125 */     double pz = Interpolations.lerp(particle.prevPosition.z, particle.position.z, partialTicks);
/* 126 */     float angle = Interpolations.lerp(particle.prevRotation, particle.rotation, partialTicks);
/*     */     
/* 128 */     Vector3d pos = calculatePosition(emitter, particle, px, py, pz);
/* 129 */     px = pos.x;
/* 130 */     py = pos.y;
/* 131 */     pz = pos.z;
/*     */ 
/*     */     
/* 134 */     int light = this.lit ? 15728880 : emitter.getBrightnessForRender(partialTicks, px, py, pz);
/* 135 */     int lightX = light >> 16 & 0xFFFF;
/* 136 */     int lightY = light & 0xFFFF;
/*     */     
/* 138 */     calculateFacing(emitter, particle, px, py, pz);
/*     */     
/* 140 */     this.rotation.rotZ(angle / 180.0F * 3.1415927F);
/* 141 */     this.transform.mul(this.rotation);
/* 142 */     this.transform.setTranslation(new Vector3f((float)px, (float)py, (float)pz));
/*     */     
/* 144 */     for (Vector4f vertex : this.vertices)
/*     */     {
/* 146 */       this.transform.transform((Tuple4f)vertex);
/*     */     }
/*     */     
/* 149 */     float u1 = this.u1 / this.textureWidth;
/* 150 */     float u2 = this.u2 / this.textureWidth;
/* 151 */     float v1 = this.v1 / this.textureHeight;
/* 152 */     float v2 = this.v2 / this.textureHeight;
/*     */     
/* 154 */     builder.func_181662_b((this.vertices[0]).x, (this.vertices[0]).y, (this.vertices[0]).z).func_187315_a(u1, v1).func_187314_a(lightX, lightY).func_181666_a(particle.r, particle.g, particle.b, particle.a).func_181675_d();
/* 155 */     builder.func_181662_b((this.vertices[1]).x, (this.vertices[1]).y, (this.vertices[1]).z).func_187315_a(u2, v1).func_187314_a(lightX, lightY).func_181666_a(particle.r, particle.g, particle.b, particle.a).func_181675_d();
/* 156 */     builder.func_181662_b((this.vertices[2]).x, (this.vertices[2]).y, (this.vertices[2]).z).func_187315_a(u2, v2).func_187314_a(lightX, lightY).func_181666_a(particle.r, particle.g, particle.b, particle.a).func_181675_d();
/* 157 */     builder.func_181662_b((this.vertices[3]).x, (this.vertices[3]).y, (this.vertices[3]).z).func_187315_a(u1, v2).func_187314_a(lightX, lightY).func_181666_a(particle.r, particle.g, particle.b, particle.a).func_181675_d();
/*     */     
/* 159 */     if (!particle.isCollisionTinting(emitter))
/*     */     {
/* 161 */       this.lit = tmpLit;
/*     */     }
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void renderOnScreen(BedrockParticle particle, int x, int y, float scale, float partialTicks) {}
/*     */ 
/*     */ 
/*     */   
/*     */   public void calculateUVs(BedrockParticle particle, float partialTicks) {
/* 173 */     this.w = (float)this.sizeW.get() * 2.25F;
/* 174 */     this.h = (float)this.sizeH.get() * 2.25F;
/*     */     
/* 176 */     float u = (float)this.uvX.get();
/* 177 */     float v = (float)this.uvY.get();
/* 178 */     float w = (float)this.uvW.get();
/* 179 */     float h = (float)this.uvH.get();
/*     */     
/* 181 */     if (this.flipbook) {
/*     */       
/* 183 */       int index = (int)(particle.getAge(partialTicks) * this.fps);
/* 184 */       int max = (int)this.maxFrame.get();
/*     */       
/* 186 */       if (this.stretchFPS) {
/*     */         
/* 188 */         float lifetime = (particle.lifetime <= 0) ? 0.0F : ((particle.age + partialTicks) / (particle.lifetime - particle.firstIntersection));
/*     */ 
/*     */         
/* 191 */         if (particle.getExpireAge() != -1)
/*     */         {
/* 193 */           lifetime = (particle.lifetime <= 0) ? 0.0F : ((particle.age + partialTicks) / particle.getExpirationDelay());
/*     */         }
/*     */         
/* 196 */         index = (int)(lifetime * max);
/*     */       } 
/*     */       
/* 199 */       if (this.loop && max != 0)
/*     */       {
/* 201 */         index %= max;
/*     */       }
/*     */       
/* 204 */       if (index > max)
/*     */       {
/* 206 */         index = max;
/*     */       }
/*     */       
/* 209 */       u += this.stepX * index;
/* 210 */       v += this.stepY * index;
/*     */     } 
/*     */     
/* 213 */     this.u1 = u;
/* 214 */     this.v1 = v;
/* 215 */     this.u2 = u + w;
/* 216 */     this.v2 = v + h;
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public void postRender(BedrockEmitter emitter, float partialTicks) {}
/*     */ 
/*     */ 
/*     */   
/*     */   public int getSortingIndex() {
/* 226 */     return 200;
/*     */   }
/*     */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\appearance\BedrockComponentCollisionAppearance.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */